Add aggregator CLI commands for configuration parameters - #3438
Add aggregator CLI commands for configuration parameters#3438turmelclem wants to merge 15 commits into
Conversation
There was a problem hiding this comment.
clippy found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
Test Results 5 files ± 0 209 suites ±0 50m 22s ⏱️ - 2h 24m 50s Results for commit 0f67a96. ± Comparison against base commit bf1c9b3. This pull request removes 76 and adds 24 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
ddfd41b to
10aa1ef
Compare
b51783c to
39da965
Compare
…figuration, with verifier
2d65553 to
ccb24d2
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces new aggregator CLI commands to export/import protocol configuration markers, along with a new mithril-protocol-config reader interface/model and Cardano-chain message/payload encoding support to make protocol configuration markers portable and verifiable.
Changes:
- Add
protocol-configuration export-markers/import-markersCLI commands (JSON export + datum generation/import validation). - Add protocol-configuration “tools” and dependency injection wiring to read on-chain markers and generate signed datums.
- Add
mithril-protocol-configmodels/messages (CBOR encoding) + payload signing structure + test doubles.
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| mithril-stm/Cargo.toml | Switch ciborium to workspace dependency for consistent versioning. |
| mithril-common/src/entities/type_alias.rs | Add hex-encoded secret key type alias for protocol configuration markers. |
| mithril-common/src/crypto_helper/ed25519_alias.rs | Add ED25519 type aliases for protocol configuration markers signing/verifying. |
| mithril-common/Cargo.toml | Switch ciborium to workspace dependency. |
| mithril-aggregator/src/tools/protocol_configuration.rs | New tool: verify imported configs against chain window + build signed datum + datum size check. |
| mithril-aggregator/src/tools/mod.rs | Register/export ProtocolConfigurationTools. |
| mithril-aggregator/src/test/double/dummies.rs | Add Dummy impl for HumanReadableProtocolConfiguration for tests. |
| mithril-aggregator/src/dependency_injection/containers/protocol_configuration.rs | New DI container for protocol-configuration commands. |
| mithril-aggregator/src/dependency_injection/containers/mod.rs | Export the new protocol-configuration DI container. |
| mithril-aggregator/src/dependency_injection/builder/support/compatibility.rs | Add construction + getter for a ProtocolConfigurationMarkersReader (prod vs dummy). |
| mithril-aggregator/src/dependency_injection/builder/mod.rs | Add stored dependency + container creation method for protocol-configuration commands. |
| mithril-aggregator/src/configuration.rs | Add ProtocolConfigurationReaderParameters + ConfigurationSource accessor for reader params. |
| mithril-aggregator/src/commands/protocol_configuration_command.rs | Implement CLI subcommands, JSON IO, consistency checks, datum generation. |
| mithril-aggregator/src/commands/mod.rs | Wire new ProtocolConfiguration command into main CLI. |
| internal/mithril-protocol-config/src/test/double/mod.rs | Export new dummy markers reader from test doubles. |
| internal/mithril-protocol-config/src/test/double/dummy_markers_reader.rs | Add dummy ProtocolConfigurationMarkersReader for test environments. |
| internal/mithril-protocol-config/src/test/double/dummies.rs | Add dummies for protocol-configuration marker models/messages. |
| internal/mithril-protocol-config/src/model.rs | Add protocol configuration marker model + ConfigurationComputerFromMarkers helper with fallback lookup. |
| internal/mithril-protocol-config/src/lib.rs | Export cardano_chain module publicly. |
| internal/mithril-protocol-config/src/interface.rs | Add ProtocolConfigurationMarkersReader trait. |
| internal/mithril-protocol-config/src/cardano_chain/protocol_configuration_reader.rs | Add Cardano-chain reader type for markers (currently stubbed). |
| internal/mithril-protocol-config/src/cardano_chain/payload.rs | Add payload structs and signing helper for protocol configuration markers. |
| internal/mithril-protocol-config/src/cardano_chain/mod.rs | Add Cardano-chain module exports for message/payload/reader. |
| internal/mithril-protocol-config/src/cardano_chain/message.rs | Add CBOR message/codec for protocol configuration markers. |
| internal/mithril-protocol-config/Cargo.toml | Add dependencies needed for CBOR/hex/serde + chain reader integration. |
| Cargo.toml | Add workspace ciborium dependency. |
| Cargo.lock | Lockfile updates for new deps/crate wiring. |
Suppressed comments (1)
mithril-aggregator/src/commands/protocol_configuration_command.rs:345
- User-facing CLI output contains spelling/grammar issues ("Sucessfuly write"), which makes the command output look unpolished.
println!(
"Sucessfuly write Tx datum file at {}",
self.target_path.to_string_lossy()
);
ccb24d2 to
95471fe
Compare
…rsion, signature and generating tx datum for protocol configuration command
…ct to avoid missing signing when generating protocol config tx datum
…empty read impl for cardano chain adapter
…s with fallback logic for ProtocolConfigurationReader
…d on chain configurations
protocol configutation markers
…ion consistency for protocol-configuration import command
…rification on protocol-configuration command
…m, and rework protocol-configuration command parameters
ad5d80a to
aba2fbb
Compare
…eader, and using dedicated struct for CBOR conversion
aba2fbb to
0f67a96
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 27 changed files in this pull request and generated no new comments.
Suppressed comments (10)
internal/mithril-protocol-config/src/cardano_chain/protocol_configuration_reader.rs:45
CardanoChainProtocolConfigurationMarkersReader::readis wired forExecutionEnvironment::Production(viaDependenciesBuilder::build_protocol_configuration_reader) but currently always returns an "not implemented yet" error. This means the new production CLI commands will fail at runtime, and it contradicts the PR/issue requirement to read on-chain markers.
async fn read(&self) -> StdResult<ConfigurationComputerFromMarkers> {
//read payload
// to ProtocolConfigurationForEpochMessage
// to ProtocolConfigurationForEpoch
// build ConfigurationComputerFromMarkers with ProtocolConfigurationForEpoch
Err(anyhow::anyhow!(
"CardanoChainProtocolConfigurationMarkersReader::read is not implemented yet"
))
mithril-aggregator/src/commands/protocol_configuration_command.rs:345
- Typo in user-facing output: "Sucessfully" should be "Successfully".
println!(
"Sucessfully wrote Tx datum file at {}",
self.target_path.to_string_lossy()
);
mithril-aggregator/src/commands/protocol_configuration_command.rs:310
fs::read_to_stringis stored as aResultand then immediately?-unwrapped insideserde_json::from_str. This is harder to read than unwrapping once and passing theStringto serde.
let json_protocol_configurations = fs::read_to_string(&self.import_path);
//2 - Parse the json into a protocol configuration list using serde_json
println!("Json parsing ...");
let protocol_configurations: Vec<HumanReadableProtocolConfiguration> =
serde_json::from_str(&json_protocol_configurations?)?;
mithril-aggregator/src/tools/protocol_configuration.rs:157
- This tool code uses
println!for reporting datum size even though the rest of the module usessloglogging. Using the logger keeps output consistent and configurable (and avoids mixing stdout/stderr in services).
println!("Datum size: {:.2} KB", size_kb);
mithril-aggregator/src/tools/protocol_configuration.rs:31
- Typo in error message: "the same has configuration" should be "the same as configuration".
#[error("Configuration to import for {0:?} is not the same has configuration on chain")]
NotSameConfigurationForEpoch(Epoch),
mithril-aggregator/src/commands/protocol_configuration_command.rs:227
- Typo in user-facing output: "Sucessfully" should be "Successfully".
This issue also appears on line 342 of the same file.
println!(
"Sucessfully wrote JSON protocol configurations file at {}",
self.target_path.to_string_lossy()
);
mithril-aggregator/src/tools/protocol_configuration.rs:83
get_on_chain_configurations(self)consumes the wholeProtocolConfigurationTools, which is surprising for a getter and prevents calling other methods afterward. Consider taking&selfand returning a clone (or returning a reference) so the tools instance remains usable.
pub fn get_on_chain_configurations(self) -> ConfigurationComputerFromMarkers {
self.configuration.on_chain_configurations
}
mithril-aggregator/src/configuration.rs:204
- This newly added
ConfigurationSource::protocol_configuration_reader_parametersdefault implementation usespanic!. Since this method is used to build production dependencies, leaving it as a panicking default increases the risk of runtime crashes if an implementation forgets to override it. Prefer making it a required method (no default) or returning aResultwith a proper error.
/// Protocol configuration reader adapter parameters
fn protocol_configuration_reader_parameters(&self) -> ProtocolConfigurationReaderParameters {
panic!("protocol_configuration_reader_parameters is not implemented.");
}
internal/mithril-protocol-config/src/cardano_chain/payload.rs:93
ProtocolConfigurationMarkersPayload::signmaps serialization errors frommessage_to_bytes()intoCreateSignature, which misclassifies the failure (and discards the more specificSerializeMessagevariant). The serialization error should be propagated as-is before signing.
let signature =
signer.sign(&self.message_to_bytes().map_err(|e| {
ProtocolConfigurationMarkersPayloadError::CreateSignature(e.into())
})?);
mithril-aggregator/src/commands/protocol_configuration_command.rs:3
MapandValueare imported fromconfigbut never used in this file; this will trigger unused-import warnings (CI should be warning-free).
This issue also appears on line 305 of the same file.
use config::{ConfigBuilder, Map, Value, builder::DefaultState};
| #[error("could not verify signature")] | ||
| VerifySignature(#[source] StdError), | ||
|
|
||
| /// Error raised when the signing the markers |
| use crate::{dependency_injection::DependenciesBuilder, tools::ProtocolConfigurationTools}; | ||
|
|
||
| #[derive(Debug, Error)] | ||
| pub enum UserConfImportVerificationError { |
There was a problem hiding this comment.
| pub enum UserConfImportVerificationError { | |
| pub enum InputConfigurationImportVerificationError { |
There was a problem hiding this comment.
All pub struct should have a doc comment. In particular, the one associated to the command is used by clap to create the help of the CLI:
Commands:
genesis Genesis tools
era Era tools
serve Server runtime mode
tools List of tools to upkeep the aggregator
database Database tools
protocol-configuration
help Print this message or the help of the given subcommand(s)
| #[error("Protocol parameters must be non-zero: {0:?}")] | ||
| ZeroValueProtocolParameters(ProtocolParameters), | ||
|
|
||
| #[error("enabled_signed_entity_types contains '{0:?}' without any associated configuration")] |
There was a problem hiding this comment.
This error message is not clear.
| root_logger: Logger, | ||
| config_builder: ConfigBuilder<DefaultState>, | ||
| ) -> StdResult<()> { | ||
| // 0 conf & dependencies |
There was a problem hiding this comment.
All comments in the execute function of this command and the following one could follow the same pattern: // X: comment.
| on_chain_markers.insert(Epoch(38), fake_configuration('A')); //conf outside offset window | ||
| on_chain_markers.insert(Epoch(44), fake_configuration('B')); //conf inside offset window |
There was a problem hiding this comment.
IMO these comments can be removed as they don't bring a lot (and they lack correct formatting).
| } | ||
|
|
||
| /// Encode this payload to a json hex string | ||
| pub fn to_json_hex(&self) -> StdResult<String> { |
There was a problem hiding this comment.
We probably miss some golden tests here?
| }; | ||
|
|
||
| /// The cbor representation of a [ProtocolConfigurationForEpochMessage] | ||
| pub type CborProtocolConfigurationForEpochMessage = String; |
| Ok(hex::encode(self.to_cbor_bytes()?)) | ||
| } | ||
|
|
||
| /// Deserialize a type `T: Serialize + DeserializeOwned` from CBOR bytes representation. |
There was a problem hiding this comment.
This comment and the one below probably need to be adjusted.
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
Golden tests are also welcome here.
Content
aggregator cli :
protocol-config :
Pre-submit checklist
Issue(s)
this PR closes #3392